package task.job;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.Instant;

@Component
public class AsyncJob {
    // 默认是同步任务
//    @Scheduled(cron = "00,02,04 * * * * ?")
//    public void syncTask() throws InterruptedException {
//        System.out.println(Instant.now());
//        Thread.sleep(3000);
//        System.out.println("00和04会执行，02不会执行");
//    }

    // 需要@EnableAsync开启多线程
//    @Async
//    @Scheduled(cron = "00,02,04 * * * * ?")
//    public void asyncTask() {
//        System.out.println(Instant.now());
//        Thread.sleep(3000);
//        System.out.println("00、02、04都会执行");
//    }
}
